package com.chinasoft.goodsManager.servlet;

import com.alibaba.fastjson.JSON;
import com.chinasoft.goodsManager.daomaingoodslist.Goods;
import com.chinasoft.goodsManager.goodslistserver.impl.ListServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class GoodsListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询数据库
        response.setContentType("text/html;charset=UTF-8");
        ListServiceImpl listService = new ListServiceImpl();
        List<Goods> query = listService.query();
        String s = JSON.toJSONString(query);
        //调用方法
        response.getWriter().write(s);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
